﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using JupiterLibrary;
using KinectXNATools;

namespace KinnectInput.KinectMetro
{
    public class KinectMetroStringButton:KinectMetroBtn
    {
        public string []Text { get; private set; }
        public Point GlobalPosition { get; private set; }
        Texture2D inActiveTex;
        Texture2D ActiveTex;
        public KinectMetroStringButton(Vector2 position, Rectangle r, Texture2D backGroundImage, string [] text)
        {
            this.Position = position;
            this.Bounds = r;
            this.BackGroundImage = new Sprite();
            this.BackGroundImage.SetRectangle(this.Bounds);
            this.BackGroundImage.Texture = backGroundImage;
            this.inActiveTex = backGroundImage;
            Color[] ActiveColor = new Color[backGroundImage.Width * backGroundImage.Height];
            backGroundImage.GetData(ActiveColor);
            for (int i = 0; i < ActiveColor.Length; i++)
            {
                ActiveColor[i].R += 10;
                ActiveColor[i].G += 10;
                ActiveColor[i].B += 10;
            }
            Texture2D tex = new Texture2D(MenuStyle.graphicsDevice, backGroundImage.Width, backGroundImage.Height);
            tex.SetData(ActiveColor);
            this.ActiveTex = tex;
            this.Text = text;
            GlobalPosition = Point.Zero;
        }
        public override void Build(KinectMetroButtonGrp parent)
        {
            this.Parent = parent;
            Parent.EnterArea += new ItemAreaEnterHandler(Parent_EnterArea);
            Parent.LeaveArea += new ItemAreaLeaveHandler(Parent_LeaveArea);
            Update();
        }

        void Parent_LeaveArea(object sender, EventArgs e)
        {
            this.BackGroundImage.Texture = inActiveTex;
        }

        void Parent_EnterArea(object sender, EnterAreaEventArgs e)
        {
            this.BackGroundImage.Texture = ActiveTex;
        }
        public override void Update()
        {
            GlobalPosition = XNAMathHelper.ToPoint(Parent.Parent.Position + Parent.Position + this.Position);
            this.Bounds = new Rectangle(GlobalPosition.X, GlobalPosition.Y, Bounds.Width, Bounds.Height);
            BackGroundImage.SetRectangle(Bounds);
            BackGroundImage.Update();
        }
        public override void Draw()
        {
            BackGroundImage.Draw();
        }
        public void DrawString(SpriteBatch sb)
        {
            Vector2 pos = new Vector2(GlobalPosition.X + MenuItemSizes.separation, GlobalPosition.Y + MenuItemSizes.separation);
            foreach (string s in this.Text)
            {
                sb.DrawString(CrossApplicationItems.TextButtonSpriteFont, s, pos, Color.White);
                pos.Y += CrossApplicationItems.TextButtonSpriteFont.MeasureString(s).Y;
            }
        }
    }
}
